package vip.xiaomoli.validator.validators;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import vip.xiaomoli.validator.constraints.InArray;

public class InArrayValidator implements ConstraintValidator<InArray, Object> {

    private String[] arr;

    @Override
    public void initialize(InArray inArray) {
        arr = inArray.value();
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        if (null == value || "".equals(value.toString().trim())) return true;
        for (String str : arr) {
            if (str.equals(value.toString())) return true;
        }
        return false;
    }

}
